package com.definesys.smecrailtransit.module.Navigation.NavigationAdapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.definesys.smecrailtransit.MainActivity;
import com.definesys.smecrailtransit.R;

import java.util.ArrayList;

/**
 * Created by cjy on 2017/8/13.
 */

public class NavigationAdapter extends BaseAdapter {

    public static final String NAVIGATION="NAVIGATION";

    private Context context;

    private ArrayList<String> naviString=new ArrayList<>();
    private ArrayList<Integer> naviPhoto=new ArrayList<>();

    public NavigationAdapter(Context context){
        this.context = context;
        _initNaviMsg();
    }

    private void _initNaviMsg(){
        naviString.add("实时消息");
        naviString.add("车站一键查询");
        naviString.add("实时状态");
        naviString.add("故障统计");
        naviString.add("运行时长");
        naviString.add("日报/月报");
        naviPhoto.add(R.drawable.real_time_msg);
        naviPhoto.add(R.drawable.site_details);
        naviPhoto.add(R.drawable.real_time_status);
        naviPhoto.add(R.drawable.fault_statistics);
        naviPhoto.add(R.drawable.operator_status);
        naviPhoto.add(R.drawable.line_report);
    }

    public final class ViewHolder {
        public TextView text;
        public ImageView imageView;
    }

    @Override
    public int getCount() {
        return this.naviString.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = new ViewHolder();
        convertView = LayoutInflater.from(this.context).inflate(R.layout.layout_navigation_item, null);
        viewHolder.text = (TextView) convertView.findViewById(R.id.text);
        viewHolder.text.setText(naviString.get(position));
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, MainActivity.class);
                intent.putExtra(NAVIGATION,position+"");
                context.startActivity(intent);
            }
        });
        viewHolder.imageView=(ImageView)convertView.findViewById(R.id.img);
        viewHolder.imageView.setBackground(context.getResources().getDrawable(naviPhoto.get(position)));
        return convertView;
    }
}
